package com.lvhx.springboot.springbatch.readfile;

import org.springframework.batch.core.step.skip.SkipLimitExceededException;
import org.springframework.batch.core.step.skip.SkipPolicy;

/**
 * @auther 吕宏旭
 * @date 2019/9/5 11:00
 * 自定义异常策略实现类
 */
public class ExceptionSkipPolicy implements SkipPolicy {

    private Class<? extends Exception> exceptionClassToSkip;
    public ExceptionSkipPolicy(Class<? extends Exception> exceptionClassToSkip){
        super();
        this.exceptionClassToSkip = exceptionClassToSkip;
    }

    @Override
    public boolean shouldSkip(Throwable throwable, int i) throws SkipLimitExceededException {
        return exceptionClassToSkip.isAssignableFrom(throwable.getClass());
    }
}
